package com.yao.fin.entity.dto;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yao.common.enums.business.fin.CourseBase;
import com.yao.common.enums.business.fin.LabelEnum;
import com.yao.common.enums.business.fin.SingleEnum;
import com.yao.fin.entity.FinancialTemplateEntity;
import lombok.Data;
import lombok.ToString;

import java.time.DayOfWeek;
import java.time.LocalDate;

/**
 * 财务模版表
 *
 * @author autoCode
 * @version 1.0.0-SNAPSHOT
 * @date 2020-04-09
 */
@Data
@TableName("fin_financial_template")
@ToString(callSuper = true)
public class FinancialTemplateDto extends FinancialTemplateEntity {

    public FinancialTemplateDto(){}

    @TableField(exist = false)
    private LocalDate beginDate;

    @TableField(exist = false)
    private LocalDate endDate;

    @TableField(exist = false)
    private Integer labelQo;

    /**
     * 1-下一周
     */
    @TableField(exist = false)
    private Integer dateType;

    @TableField(exist = false)
    private String labelDesc;

    @TableField(exist = false)
    private String singleDesc;

    @TableField(exist = false)
    private String courseDesc;


    public FinancialTemplateDto buildParams(){
        if(null != this.dateType && 0 != this.dateType){
            LocalDate currentDate = LocalDate.now();

            // 下周的今天
            LocalDate sameDateNextWeek = currentDate.plusWeeks(1);

            // 下周的周一
            LocalDate monday = sameDateNextWeek.with(DayOfWeek.MONDAY);

            // 下周的周五
            LocalDate friday = sameDateNextWeek.with(DayOfWeek.FRIDAY);

            beginDate = monday;

            endDate = friday;
        }

        return this;
    }

    public FinancialTemplateDto fill(){
        singleDesc = SingleEnum.getDesc(getSingle());

        if(LabelEnum.ZJ == getLabel()){
            courseDesc = CourseBase.ZJEnum.getDesc(getCourse());
        }else if(LabelEnum.CPA == getLabel()){
            courseDesc = CourseBase.CPAEnum.getDesc(getCourse());
        }
        labelDesc = getLabel().getDesc();

        return this;
    }
}